package com.dzl.movie;

import com.dzl.base.controller.BaseController;
import com.dzl.moive.pojo.WelfareMovieCity;
import com.dzl.moive.service.WelfareMovieCityService;
import com.dzl.util.EmptyUtils;
import com.dzl.util.JsonResult;
import com.dzl.util.LocationEntity;
import com.dzl.util.LocationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 电影城市(welfare_movie_city)表控制层
 * @author liuguanjun
 * @date 2021-11-02 11:50:29
 */
@RestController
@RequestMapping("/welfareMovieCity")
public class WelfareMovieCityController extends BaseController {

    @Autowired
    private WelfareMovieCityService service;

    /**
     * 获取用户当前地址信息
     * @param lon 经度
     * @param lat 纬度
     * @author liuguanjun
     * @date 2021-11-02 17:17:50
     **/
    @GetMapping(value = "getLocation")
    public JsonResult<LocationEntity> getLocation(String lon,String lat) {
        if(EmptyUtils.isEmpty(lon)){
            lon = "114.326707";
        }
        if(EmptyUtils.isEmpty(lat)){
            lat = "30.460249";
        }
        LocationEntity locationEntity = LocationUtil.getLocation(lat,lon);
        if(EmptyUtils.isNotEmpty(locationEntity)){
            WelfareMovieCity city = service.getCityByCityName(locationEntity.getCity());
            if(EmptyUtils.isNotEmpty(city)){
                locationEntity.setCity(city.getName());
                locationEntity.setCitycode(city.getCitycode());
            }
        }
        return JsonResult.success(locationEntity);
    }

    /**
     * 获取城市列表
     * @param cityName 城市名称
     * @author liuguanjun
     * @date 2021-11-02 11:54:50
     **/
    @GetMapping(value = "getCityList")
    public JsonResult<List<WelfareMovieCity>> getCityList(String cityName) {
        return JsonResult.success(service.getCityList(cityName,null));
    }

    /**
     * 获取区县列表
     * @param citycode 城市编码
     * @author liuguanjun
     * @date 2021-11-03 14:48:50
     **/
    @GetMapping(value = "getCountyList")
    public JsonResult<List<WelfareMovieCity>> getCountyList(String citycode) {
        if(EmptyUtils.isEmpty(citycode)){
            return JsonResult.failWithMsg("缺少参数:城市编码[citycode]");
        }
        return JsonResult.success(service.getCountyList(citycode));
    }

}
